import mongoose from "mongoose";

const ChatSchema = new mongoose.Schema(
  {
    chatId: { type: Number, index: true, unique: true, required: true },
    title: { type: String },
    type: { type: String },
    createdAt: { type: Date },
    updatedAt: { type: Date },
  },
  {
    timestamps: { createdAt: true, updatedAt: true, currentTime: () => new Date() },
    virtuals: {
      parsedChatId: {
        get() {
          const chatId = String(this.chatId);
          return chatId.startsWith("-100") ? chatId.slice(3) : chatId;
        },
      },
    },
  },
);

export const Chat = mongoose.model("Chat", ChatSchema);
